//
//  QuickCardLogic.m
//  QRMaster
//
//  Created by myApple on 16/5/30.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "QuickCardLogic.h"
#import "OperationDataBaseModel.h"

@interface QuickCardLogic ()
{
    OperationDataBaseModel * operation;
}
@end

@implementation QuickCardLogic

#pragma mark - 插入收藏卡
-(void)insertQuickCard:(QuickCardModel *)model
{
    NSMutableDictionary * communityListDict = [[NSMutableDictionary alloc]init];
    [communityListDict setValue:model.communityId forKey:@"communityId"];
    [communityListDict setValue:model.communityName forKey:@"communityName"];
    [communityListDict setValue:model.buildingName forKey:@"buildingName"];
    [communityListDict setValue:model.floorName forKey:@"floorName"];
    [communityListDict setValue:model.roomId forKey:@"roomId"];
    [communityListDict setValue:model.roomName forKey:@"roomName"];
    [communityListDict setValue:model.collectId forKey:@"collectId"];
    [communityListDict setValue:[NSString stringWithFormat:@"%ld",(long)model.index] forKey:@"collectIndex"];
    [communityListDict setValue:model.customerName forKey:@"collectionCardName"];
    [communityListDict setValue:model.imageURL forKey:@"imageUrl"];
    operation = [[OperationDataBaseModel alloc]init];
    [operation insertDataTable:@"collectionCard" withDict:communityListDict];
}

#pragma mark - 删除收藏卡
-(void)deleteQuickCard:(NSString *)communityId roomId:(NSString *)roomId
{
    NSString * condition = [NSString stringWithFormat:@"where communityId = %@ and roomId = %@",communityId,roomId];
    operation = [[OperationDataBaseModel alloc]init];
    [operation deleteDataFromTable:@"collectionCard" withCondition:condition];
}

#pragma mark - 查询房卡
-(void)queryAllQuickCardBlock:(quickCardBlock)quickCardArrayBlock
{
    __block NSMutableArray * quickCardArray = [[NSMutableArray alloc]init];
    operation = [[OperationDataBaseModel alloc]init];
    [operation queryDataFromTable:@"collectionCard" withCondition:@"" block:^(FMResultSet *set) {
        while ([set next]) {
            QuickCardModel * model=[[QuickCardModel alloc]init];
            model.communityId=[set stringForColumn:@"communityId"];
            model.communityName=[set stringForColumn:@"communityName"];
            model.buildingName=[set stringForColumn:@"buildingName"];
            model.floorName=[set stringForColumn:@"floorName"];
            model.roomName=[set stringForColumn:@"roomName"];
            model.roomId=[set stringForColumn:@"roomId"];
            model.collectId=[set stringForColumn:@"collectId"];
            model.index=[[set stringForColumn:@"collectIndex"] integerValue];
            model.customerName=[set stringForColumn:@"collectionCardName"];
            model.imageURL = [set stringForColumn:@"imageUrl"];
            [quickCardArray addObject:model];
        }
        if (quickCardArrayBlock) {
            quickCardArrayBlock(quickCardArray);
        }
    }];
}


@end
